﻿using System;
using AdaptiveAgents.Agents;
using AdaptiveAgents.Agents.Predicters;
using System.Collections.Generic;
using AdaptiveAgents.Loggers;

namespace AdaptiveAgents.Agents.Predicters
{
    /// <summary>
    /// Represents a default predicter
    /// </summary>
    class NormalNextPlayerPredicter : NextPlayerPredicter
    {
        public NormalNextPlayerPredicter(Agent agent)
            : base(agent)
        {
            agent.NextPlayerPredicter = this;
        }

        /// <summary>
        /// Default Predicter.
        /// Predicts next performer that the agent will pick according to max competence
        /// </summary>
        /// <param name="agentID"></param>
        /// <returns></returns>
        public override List<int> predict()
        {
            //predict next performer that the agent will pick

            List<int> intlist = new List<int>();
            double maxComp = -Double.MaxValue;
            foreach (Agent ag in _me.Environment.agents)
            {
                double comp;
                comp = _me.getTeammateModel(ag.ID).EstimateCompetence();
                if (comp > maxComp)
                {
                    intlist.Clear();
                    maxComp = comp;
                    intlist.Add(ag.ID);
                }
                else if (Math.Abs(comp - maxComp) < .000001)
                {
                    intlist.Add(ag.ID);
                }
            }

            AdaptiveAgents.logger.Write(MessageType.HackMessage, "Agent {0} should select one of ", _me.ID);
            AdaptiveAgents.logger.Write(MessageType.HackMessage, "{");
            foreach (int i in intlist)
                AdaptiveAgents.logger.Write(MessageType.HackMessage, "{0},", i);
            AdaptiveAgents.logger.WriteLine(MessageType.HackMessage, "}");

            return intlist;
        }
    }
}
